package com.czh.springboot04.service.serviceimpl;

import com.czh.springboot04.entity.Free;
import com.czh.springboot04.mapper.FreeMapper;
import com.czh.springboot04.service.FreeService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class FreeServiceImpl implements FreeService {
    @Autowired
   private FreeMapper freeMapper;
    @Override
    public int freeAdd(Free free) {
        int i = freeMapper.freeAdd(free);
        return i;
    }

    @Override
    public int freeUpdate(Free free) {
        int i = freeMapper.freeUpdate(free);
        return i;
    }

    @Override
    public int freeDelete(int id) {
        int i = freeMapper.freeDelete(id);
        return i;
    }

    @Override
    public PageInfo<Free> freeSelectAll(int pageNum, int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<Free> freeList = freeMapper.freeSelectAll();
        PageInfo<Free> pageInfo = new PageInfo<>(freeList);
        return pageInfo;
    }

    @Override
    public PageInfo<Free> freeSelectByName(int pageNum, int pageSize, String name) {
        PageHelper.startPage(pageNum,pageSize);
        List<Free> freeList = freeMapper.freeSelectByName(name);
        PageInfo<Free> pageInfo = new PageInfo<>(freeList);
        return pageInfo;
    }
}
